var a = require("../../../@babel/runtime/helpers/defineProperty"), t = require("../../../mybehaviors/location/location"), e = getApp();

Page({
    behaviors: [ t ],
    data: {
        tabShow: !0,
        language: "",
        tabIndex: 0,
        privilege_discount_show: !0,
        weekday_discount_show: !1,
        exclusive_coupons_show: !1,
        pd_index: 0,
        pd_date_index: 0,
        wd_index: 0,
        pd_classfy_arr: [],
        pd_date_arr: [],
        pd_category_id: 0,
        wd_category_id: 0,
        pd_date: {},
        wd_discount: "",
        card_status: !1,
        card_bk: "",
        pd_loading: !1,
        pd_allLoaded: !1,
        pd_goload: !0,
        pd_isLoadMore: !0,
        pd_page: 1,
        pd_total_page: 0,
        pd_arr: [],
        ec_loading: !1,
        ec_allLoaded: !1,
        ec_goload: !0,
        ec_isLoadMore: !0,
        ec_page: 1,
        ec_total_page: 0,
        ec_arr: [],
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        info: {},
        tabArr: []
    },
    onLoad: function(a) {
        var t = this;
        this.initData(), this._getLocation(function() {
            t.getCardIndex();
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    initData: function() {
        this.setData({
            privilege_discount_show: !0,
            weekday_discount_show: !1,
            exclusive_coupons_show: !1,
            tabIndex: 0,
            pd_index: 0,
            pd_date_index: 0,
            wd_index: 0,
            pd_classfy_arr: [],
            pd_date_arr: [],
            pd_category_id: 0,
            wd_category_id: 0,
            pd_date: {},
            wd_discount: "",
            card_status: !1,
            card_bk: ""
        }), this.pdInitData(), this.ecInitData();
    },
    pdInitData: function() {
        this.setData({
            pd_loading: !1,
            pd_allLoaded: !1,
            pd_goload: !0,
            pd_isLoadMore: !0,
            pd_page: 1,
            pd_total_page: 0,
            pd_arr: []
        });
    },
    ecInitData: function() {
        this.setData({
            ec_loading: !1,
            ec_allLoaded: !1,
            ec_goload: !0,
            ec_isLoadMore: !0,
            ec_page: 1,
            ec_total_page: 0,
            ec_arr: []
        });
    },
    getCardIndex: function() {
        var t = this, d = e.getNetAddresss("plugin.universal-card.api.home.index");
        e._getNetWork({
            url: d,
            success: function(d) {
                var o, i, n = d.data;
                1 == n.result ? (t.setData((o = {
                    card_status: !0,
                    info: n.data
                }, a(o, "tabArr[0]", n.data.privilege_name), a(o, "tabArr[1]", n.data.coupon_name), 
                a(o, "titles", n.data.title), o)), e._isTextEmpty(t.data.tabArr[0]) && e._isTextEmpty(t.data.tabArr[1]) && t.setData({
                    tabShow: !1
                }), wx.setNavigationBarTitle({
                    title: t.data.titles
                }), t.getClassfyData(), t.getEcData()) : (t.setData((i = {
                    card_status: !1,
                    card_bk: n.data.card_thumb
                }, a(i, "tabArr[0]", n.data.privilege_name ? n.data.privilege_name : ""), a(i, "tabArr[1]", n.data.coupon_name ? n.data.coupon_name : ""), 
                a(i, "titles", n.data.title), i)), e._isTextEmpty(t.data.tabArr[0]) && e._isTextEmpty(t.data.tabArr[1]) && t.setData({
                    tabShow: !1
                }), wx.setNavigationBarTitle({
                    title: t.data.titles
                }), t.getClassfyData());
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getClassfyData: function() {
        var a = this, t = e.getNetAddresss("plugin.universal-card.frontend.store-discount.store-data");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    pd_classfy_arr: e.data.store_category,
                    pd_date_arr: e.data.date_time,
                    pd_category_id: e.data.store_category[0].id,
                    pd_date: e.data.date_time[0],
                    wd_category_id: e.data.store_category[0].id
                }), a.pdInitData(), a.getPdData()) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getPdData: function() {
        var a = this, t = e.getNetAddresss("plugin.universal-card.frontend.store-discount.privilege");
        t += "&lng=" + this.data.point.lng, t += "&lat=" + this.data.point.lat, t += "&week=" + this.data.pd_date.week_num, 
        t += "&category_id=" + this.data.pd_category_id, t += "&day=" + this.data.pd_date.day, 
        t += "&city_name=" + this.data.city, t += "&page=" + this.data.pd_page, e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    pd_total_page: e.data.last_page,
                    pd_arr: e.data.data
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getEcData: function() {
        var a = this, t = e.getNetAddresss("plugin.universal-card.frontend.index.couponList.index");
        t += "&page=" + this.data.ec_page, t += "&lng=" + this.data.point.lng, t += "&lat=" + this.data.point.lat, 
        t += "&city_name=" + this.data.city, e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    ec_total_page: e.data.last_page,
                    ec_arr: e.data.data
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    gotoOpen: function() {
        wx.navigateTo({
            url: "/packageC/o2o/card/CardOpenMembership/CardOpenMembership?"
        });
    },
    gotoFare: function() {
        var a = this.data.info;
        console.log(a), e._isTextEmpty(a.goods_spec) ? wx.navigateTo({
            url: "/packageC/o2o/card/new_card/new_card?level_id=" + a.level_id
        }) : wx.navigateTo({
            url: "/packageC/o2o/card/new_card/new_card?level_id=" + a.level_id + "&spec=goods_spec"
        });
    },
    toggle: function(a) {
        var t = a.currentTarget.dataset.index;
        this.setData({
            tabIndex: t
        }), 0 == t ? this.setData({
            privilege_discount_show: !0,
            exclusive_coupons_show: !1
        }) : 1 == t && this.setData({
            privilege_discount_show: !1,
            exclusive_coupons_show: !0
        });
    },
    pdClassfySearch: function(a) {
        var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.index;
        this.setData({
            pd_index: e,
            pd_category_id: t
        }), this.pdInitData(), this.getPdData();
    },
    pdDateSearch: function(a) {
        var t = a.currentTarget.dataset.item, e = a.currentTarget.dataset.index;
        this.setData({
            pd_date_index: e,
            pd_date: t
        }), this.pdInitData(), this.getPdData();
    },
    gotoShop: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t
        });
    },
    getCoupon: function(a) {
        var t = a.currentTarget.dataset.id, d = e.getNetAddresss("plugin.universal-card.frontend.index.couponGet.index");
        d += "&coupon_id=" + t, e._getNetWork({
            url: d,
            success: function(a) {
                var t = a.data;
                1 == t.result ? wx.showToast({
                    icon: "none",
                    title: "领取成功",
                    duration: 1500
                }) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    gotoCouponLog: function() {
        wx.navigateTo({
            url: "/packageB/member/couponLog/couponLog"
        });
    }
});